package com.ibiaoke.goods.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.goods.entity.XcxReduceGoods;
import com.ibiaoke.goods.entity.XcxReduceGoodsDetail;
import com.ibiaoke.goods.entity.XcxReduceGoodsDetailExample;
import com.ibiaoke.goods.entity.XcxReduceGoodsExample;
import com.ibiaoke.goods.entity.vo.MarketVo;
import com.ibiaoke.goods.mapper.XcxReduceGoodsDetailMapper;
import com.ibiaoke.goods.mapper.XcxReduceGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class XcxReduceGoodsDetailDao extends BaseDao<XcxReduceGoodsDetail, XcxReduceGoodsDetailExample, Integer,XcxReduceGoodsDetailMapper> {

    @Autowired
    private XcxReduceGoodsDetailMapper xcxReduceGoodsDetailMapper;

    @Override
    public XcxReduceGoodsDetailMapper getMapper() {
        return xcxReduceGoodsDetailMapper;
    }

    public List<XcxReduceGoodsDetail> findXcxReduceGoodsDetail(String reduceCode) {
        XcxReduceGoodsDetailExample example = new XcxReduceGoodsDetailExample();
        XcxReduceGoodsDetailExample.Criteria criteria = example.createCriteria();
        criteria.andReduceCodeEqualTo(reduceCode);
        return xcxReduceGoodsDetailMapper.selectByExample(example);
    }

    public List<XcxReduceGoodsDetail> marketXcxReduceGodsDetail(MarketVo marketVo, Page page){
        XcxReduceGoodsDetailExample example = new XcxReduceGoodsDetailExample();
        XcxReduceGoodsDetailExample.Criteria criteria = example.createCriteria();
        if(marketVo.getGoodsName()!=null){
            criteria.andGoodsNameLike("%"+marketVo.getGoodsName()+"%");
        }
        if(marketVo.getGoodsId()!=null){
            criteria.andGoodsIdEqualTo(marketVo.getGoodsId());
        }
        if (marketVo.getCreateTime()!=null){
            criteria.andCreateTimeGreaterThanOrEqualTo(marketVo.getCreateTime());
        }
        if (marketVo.getEndCreateTime()!=null){
            criteria.andCreateTimeLessThanOrEqualTo(marketVo.getEndCreateTime());
        }
        if (marketVo.getShopId()!=null){
            criteria.andShopidEqualTo(marketVo.getShopId());
        }

        page.setTotalCount(xcxReduceGoodsDetailMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        return xcxReduceGoodsDetailMapper.selectByExample(example);
    }
}
